S.NodeUI.Crowding = function (data, option) {
    var me = this;
    Q.doSuperConstructor(me, S.NodeUI.Crowding, [data]);
    me.setOption(me.option);
    me.setOption(option);
    me.cMax = [me.cLight[0] - me.cDark[0], me.cLight[1] - me.cDark[1], me.cLight[2] - me.cDark[2]];
}

S.NodeUI.Crowding.prototype = {
    alpha: 0.6, // alpha透明度（0~1）
    radius: 50, // 最大半径
    degree: 0, // 归一化值，（0~1）
    cLight: [251, 233, 231], // 亮色
    cDark: [239, 138, 101], // 深色

    option: {
        zIndex: -1,
        anchorPosition: Q.Position.CENTER_MIDDLE,
        position: Q.Position.CENTER_MIDDLE
    },

    setOption: function (option) {
        var me = this;
        S.setOption(me, option);
    },

    setData: function (value) {
        var me = this;
        value = value < 0 ? 0 : value > 1 ? 1 : value;
        me.degree = value;
        if (0 == value) {
            me.visible = false;
        } else {
            me.invalidateData();
            me.visible = true;
        }
        me.data.invalidate();
    },

    measure: function () {
        var me = this, bound = me.radius * me.degree * 2;
        me.fillColor = 'rgb(' + [parseInt(me.cLight[0] - me.cMax[0] * me.degree)
            , parseInt(me.cLight[1] - me.cMax[1] * me.degree)
            , parseInt(me.cLight[2] - me.cMax[2] * me.degree)].join(',') + ')';
        me.setMeasuredBounds(bound, bound);
    },

    draw: function (g) {
        var me = this, r = me.radius * me.degree * 2;
        g.globalAlpha = me.alpha;
        g.beginPath();
        g.moveTo(0, 0);
        g.arc(r / 2, r / 2, r, 0, Math.PI * 2);
        g.closePath();
        g.fillStyle = me.fillColor;
        g.fill();
    },

    doHitTest: function (x, y, tolerance) {
        return false;
    }

};

Q.extend(S.NodeUI.Crowding, Q.BaseUI);

